<?php
namespace App\Controllers\Order;

use App\Models\Goods\Goods;
use App\Models\User\User;
use App\Models\Order\Order;

/*
 * 获取指定订单的状态;
 */
class GetPayResult extends \App\Libs\Base\BaseAction
{
    protected function beforeRun() {
        parent::beforeRun();
        $this->needLogin = TRUE;
    }
	
	public function execute(){
		$uid = $this->session->user->id;
        if(!$this->request->has('order_sn')){
            return \App\Libs\Views\Json::view(1, '缺少订单号！', null);
        }
        $order_sn = $this->request->get('order_sn');
        $matchOrder = Order::find([
            'conditions' => 'uid=?1 and order_sn=?2',
            'bind' => [1=> $uid,2=>$order_sn]
        ]);
        if($matchOrder->status=='1'){
            return \App\Libs\Views\Json::view(0, '订单支付成功!', null);
        }else{
            sleep(2);
            $secondMatchOrder = Order::find([
                'conditions' => 'uid=?1 and order_sn=?2',
                'bind' => [1=> $uid,2=>$order_sn]
            ]);
            if($secondMatchOrder->status=='1'){
                return \App\Libs\Views\Json::view(0, '订单支付成功!', null);
            }else{
                return \App\Libs\Views\Json::view(1, '订单支付结果返回中，请稍后于列表中查看!', null);
            }

        }
	}
}
